﻿using GameDesigner.Source.Widgets;
using GameLibrary.Model;
using GameLibrary.Model.Core;
using Microsoft.VisualBasic.PowerPacks;
using GameDesigner.Displayers;

namespace GameDesigner.Source.Displayers
{
    class GameDisplayerDT : GameDisplayer 
    {

        public GameDisplayerDT(GameDef game, ShapeContainer container) :
            base(game, container)
        {
            game.GamePlayerDefs.PlayerRemovedEvent += this.OnPlayerRemovedHandler;
            game.GameElementDefs.ElementRemovedEvent += this.OnElementRemoved;
        }

        private void OnPlayerRemovedHandler(GamePlayerDef player)
        {
            if (ActiveObject.Object == player)
            {
                ActiveObject.Object = null;
            }
        }

        private void OnElementRemoved(GameElementDef subject)
        {
            if (ActiveObject.Object == subject)
            {
                ActiveObject.Object = null;
            }

            foreach (ElementDisplayer displayer in base.Displayers)
            {
                if (displayer.Location == subject.Location)
                {
                    displayer.Clear();
                    break;
                }
            }
        }
   
    }
}
